using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
using LispLib;

namespace GeneticAlgorithm.CP3.BitString
{
    class Mutation
    {
        //public static float mutationRate = 0.001f;

        public static double likelihood = 0.05;

        public static Individual<int[], Interpreter.Pair> A(Individual<int[], Interpreter.Pair> parent)
        {
            int[] original = parent.Genotype;

            int[] newOne = new int[original.Length];


            double l;

            for (int i = 0; i < newOne.Length; i++)
            {
                l = Global.random.NextDouble();
                if (l > likelihood)
                {
                    //replace it with the right type
                    if (original[i] < 10)
                    {
                        //ints for ints
                        newOne[i] = Global.random.Next(0, 10);
                        //Console.WriteLine("Replacing " + original[i] + " with " + newOne[i]);

                    }
                    else if (original[i] > 12)
                    {
                        newOne[i] = Global.random.Next(13, 16);
                        //Console.WriteLine("Replacing " + original[i] + " with " + newOne[i]);
                    }
                    else //if(original[i] == 11)
                    {
                        newOne[i] = original[i];
                        //Console.WriteLine("Replacing " + original[i] + " with " + newOne[i]);
                    }


                }
                else
                {
                    newOne[i] = original[i];
                }
            }

            return new Individual(newOne, parent);

            //BitArray genotype = new BitArray(parent.Genotype);

            //// number of bits to mutate
            //int bits = (int)(mutationRate * parent.Genotype.Count);
            //if (bits == 0)
            //{
            //    // flip at least one bit
            //    bits = 1;
            //}

            //for (int i = 0; i < bits; i++)
            //{
            //    int index = Global.random.Next(parent.Genotype.Count);
            //    genotype[index] = !genotype[index];
            //}

            //Individual<BitArray, Stream> retval = new Individual1(genotype);
            //return retval;
        }
    }
}
